import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'HomeDefault',
    component: () => import(/* webpackChunkName: "common" */ '../views/home.vue')
  },
  {
    path: '/404',
    name: 'notFound',
    component: () => import(/* webpackChunkName: "common" */ '../views/404.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  routes
})

const childrenPath = ['/app-1', '/app-2']
router.beforeEach((to, from, next) => {
  if (to.name) { // 有 name 属性，说明是主应用的路由
    next()
  } else if (childrenPath.some(item => to.path.includes(item))) {
    next()
  } else {
    next({ name: 'notFound' })
  }
})

export default router
